package com.zjitc.config;


import javax.sql.DataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;

/**
 * Create by IntelliJ IDEA
 *
 * @author: ate-Time: 2018/3/12 13:47
 * @description:
 */

@Configuration
@Import(DataSourceConfiguration.class)
public class MyBatisXmlConfiguration {
  public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource){
    SqlSessionFactoryBean sqlSessionFactoryBean=new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setMapperLocations(new Resource[]{new FileSystemResource("D:\\project\\company_fire\\demo04-spring4\\src\\main\\resources\\spring-mybatis-xml-config.xml")});
    return sqlSessionFactoryBean;
  }

public MapperScannerConfigurer mapperScannerConfigurer(){
    MapperScannerConfigurer mapperScannerConfigurer=new MapperScannerConfigurer();
    mapperScannerConfigurer.setBasePackage("com.zjitc.mapper" );
    mapperScannerConfigurer.setSqlSessionFactoryBeanName("SqlSessionFactoryBean");
    return mapperScannerConfigurer;
}
}
